//C8.7:strquote.cpp -- different disigns
#include <iostream>
#include <string>
using namespace std;

string version1(const string & s1, const string & s2);
const string & version2(string & s1, const string & s2);
const string & vresion3(string & s1, const string & s2);

int main(void)
{
    string input;
    string copy;
    string result;

    cout << "Enter a string: ";
    getline(cin, input);
    copy = input;
    cout << "Your string as entered: " << result << '\n';
    result = version1(input, "***");
    cout << "Your string enhanced: " << result << '\n';
    cout << "Your original string: " << input << '\n';

    result = version2(input, "###");
    cout << "Your string enhanced: " << result << '\n';
    cout << "Your original string: " << input << '\n';

    cout << "Resetting original string.\n";
    input = copy;
    result = vresion3(input, "@@@");
    cout << "Your string enhanced: " << result << '\n';
    cout << "Your original string: " << input << '\n';

    return 0;
}

string version1(const string & s1, const string & s2)
{
    string temp;
    temp = s2 + s1 + s2;
    return temp;
}

const string & version2(string & s1, const string & s2)    // has side effect
{
    s1 = s2 + s1 + s2;
    // safe to return reference passed to function
    return s1;
}

const string & version3(string & s1, const string & s2)    // bad design
{
    string temp;
    temp = s2 + s1 + s2;
    // unsafe to return reference to local variable
    return temp;
}
